home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / pdriver5.arc / PKTMODE.ASM < prev    next >
Assembly Source File  |  1989-12-17  |  7KB  |  311 lines

  1. ;  Russell Nelson, Clarkson University.  September 14, 1989
  2. ;  Copyright, 1989, Russell Nelson
  3.  
  4. ;   This program is free software; you can redistribute it and/or modify
  5. ;   it under the terms of the GNU General Public License as published by
  6. ;   the Free Software Foundation, version 1.
  7. ;
  8. ;   This program is distributed in the hope that it will be useful,
  9. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ;   GNU General Public License for more details.
  12. ;
  13. ;   You should have received a copy of the GNU General Public License
  14. ;   along with this program; if not, write to the Free Software
  15. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  
  17.     include    defs.asm
  18.  
  19. code    segment byte public
  20.     assume    cs:code, ds:code
  21.  
  22.     org    80h
  23. phd_dioa    label    byte
  24.  
  25.     org    100h
  26. start:
  27.     jmp    start_1
  28.  
  29. their_isr    dd    ?
  30. packet_int_no    db    ?,?
  31. packet_mode    dw    -1
  32.  
  33. handle        dw    0
  34. this_mode    dw    ?
  35. bogus_type    db    1,2,3,4,5,6,7,8        ;totally bogus type code.
  36.  
  37. signature    db    'PKT DRVR',0
  38. signature_len    equ    $-signature
  39. no_signature_msg    db    "No packet driver at that address",'$'
  40. usage_msg    db    "usage: pktmode <packet_int_no> [<mode>]",'$'
  41. bad_handle_msg    db    "Bad handle error",'$'
  42. bad_mode_msg    db    "Bad mode error",'$'
  43. bad_error_msg    db    "Unknown error",'$'
  44.  
  45. not_implemented    db    "xx ",'$'
  46. current_mode    db    "-> ",'$'
  47. two_spaces    db    "   ",'$'
  48.  
  49. mode_names    dw    mode_1_msg,mode_2_msg,mode_3_msg,mode_4_msg
  50.         dw    mode_5_msg,mode_6_msg
  51.  
  52. mode_1_msg    db    "1) Turn off receiver",CR,LF,'$'
  53. mode_2_msg    db    "2) Receive only packets sent to this interface",CR,LF,'$'
  54. mode_3_msg    db    "3) Mode 2 plus broadcast",CR,LF,'$'
  55. mode_4_msg    db    "4) Mode 3 plus limited multicast",CR,LF,'$'
  56. mode_5_msg    db    "5) Mode 3 plus all multicast",CR,LF,'$'
  57. mode_6_msg    db    "6) All packets",CR,LF,'$'
  58.  
  59.  
  60. usage_error:
  61.     mov    dx,offset usage_msg
  62. error:
  63.     mov    ah,9
  64.     int    21h
  65.     jmp    all_done
  66.  
  67. start_1:
  68.     mov    si,offset phd_dioa+1
  69.     cmp    byte ptr [si],CR    ;end of line?
  70.     je    usage_error
  71.  
  72.     mov    di,offset packet_int_no
  73.     call    get_number
  74.     mov    di,offset packet_mode
  75.     call    get_number
  76.  
  77.     mov    ah,35h            ;get their packet interrupt.
  78.     mov    al,packet_int_no
  79.     int    21h
  80.     mov    their_isr.offs,bx
  81.     mov    their_isr.segm,es
  82.  
  83.     lea    di,3[bx]
  84.     mov    si,offset signature
  85.     mov    cx,signature_len
  86.     repe    cmpsb
  87.     je    signature_ok
  88.     mov    dx,offset no_signature_msg
  89.     jmp    error
  90. bad_j_1:
  91.     jmp    bad
  92. signature_ok:
  93.  
  94.     mov    ah,2            ;access all packets.
  95.     mov    al,1            ;Ethernet class.
  96.     mov    bx,-1            ;generic type.
  97.     mov    dl,0            ;generic number.
  98.     mov    cx,MAX_P_LEN        ;use the max type length.
  99.     mov    si,offset bogus_type
  100.     push    cs            ;es:di -> our receiver.
  101.     pop    es
  102.     mov    di,offset our_recv
  103.     pushf
  104.     cli
  105.     call    their_isr
  106.     jc    bad_j_1
  107.     mov    handle,ax
  108.  
  109.     mov    cx,packet_mode
  110.     cmp    cx,-1
  111.     je    get_mode
  112.  
  113.     mov    ah,20            ;set the receive mode.
  114.     mov    bx,handle
  115.     pushf
  116.     cli
  117.     call    their_isr
  118.     jc    bad_j_1
  119.     jmp    okay
  120. get_mode:
  121.     mov    ah,21            ;get the receive mode.
  122.     mov    bx,handle
  123.     pushf
  124.     cli
  125.     call    their_isr
  126.     jc    bad
  127.     mov    packet_mode,ax
  128.  
  129.     mov    this_mode,1        ;start trying with mode 1.
  130. try_mode:
  131.     cmp    this_mode,6        ;have we hit the last mode?
  132.     ja    no_more_modes        ;yes.
  133.  
  134.     mov    ah,20            ;set the receive mode.
  135.     mov    bx,handle
  136.     mov    cx,this_mode
  137.     pushf
  138.     cli
  139.     call    their_isr
  140.     mov    dx,offset not_implemented
  141.     jc    tried_mode        ;we tried it, and it didn't work.
  142.     mov    dx,offset current_mode
  143.     mov    cx,this_mode        ;is this the current mode?
  144.     cmp    packet_mode,cx
  145.     je    tried_mode
  146.     mov    dx,offset two_spaces
  147. tried_mode:
  148.     mov    ah,9            ;print either "  ", "xx", or "->"
  149.     int    21h
  150.  
  151.     mov    bx,this_mode        ;print the name of this mode.
  152.     shl    bx,1
  153.     mov    ah,9
  154.     mov    dx,mode_names[bx-2]
  155.     int    21h
  156.  
  157.     inc    this_mode        ;try the next mode.
  158.     jmp    try_mode
  159.  
  160. no_more_modes:
  161.  
  162.     mov    ah,20            ;set the receive mode.
  163.     mov    bx,handle
  164.     mov    cx,packet_mode
  165.     pushf
  166.     cli
  167.     call    their_isr
  168.  
  169. all_done:
  170.     xor    bx,bx            ;only release the handle once.
  171.     xchg    bx,handle
  172.     or    bx,bx
  173.     je    all_done_1        ;we've already released it.
  174.     mov    ah,3            ;release_type
  175.     pushf
  176.     cli
  177.     call    their_isr
  178.     jc    bad
  179. all_done_1:
  180.     int    20h
  181.  
  182. bad:
  183.     cmp    dh,BAD_HANDLE
  184.     jne    bad_1
  185.     mov    dx,offset bad_handle_msg
  186.     jmp    error
  187. bad_1:
  188.     cmp    dh,BAD_MODE
  189.     jne    bad_2
  190.     mov    dx,offset bad_mode_msg
  191.     jmp    error
  192. bad_2:
  193.     mov    dx,offset bad_error_msg
  194.     jmp    error
  195. okay:
  196.     jmp    all_done
  197.  
  198.  
  199. our_recv:
  200.     or    ax,ax            ;first or second call?
  201.     jne    our_recv_1        ;second -- we ignore the packet
  202.     push    cs
  203.     pop    es
  204.     mov    di,offset our_buffer
  205. our_recv_1:
  206.     retf
  207.  
  208.  
  209.     public    get_number
  210. get_number:
  211.     mov    bp,10            ;we default to 10.
  212.     jmp    short get_number_0
  213.  
  214.     public    get_hex
  215. get_hex:
  216.     mov    bp,16
  217. ;get a hex number from [si], skipping leading blanks.
  218. ;return cy if there are no digits at all.
  219. ;return nc, bx:cx = number, and store cx at [di]
  220. get_number_0:
  221.     call    skip_blanks
  222.     call    get_digit        ;is there really a number here?
  223.     jc    get_number_3
  224.     or    al,al            ;Does the number begin with zero?
  225.     jne    get_number_4        ;no.
  226.     mov    bp,8            ;yes - they want octal.
  227. get_number_4:
  228.  
  229.     xor    cx,cx            ;get a hex number.
  230.     xor    bx,bx
  231. get_number_1:
  232.     lodsb
  233.     cmp    al,'x'            ;did they really want hex?
  234.     je    get_number_5        ;yes.
  235.     cmp    al,'X'            ;did they really want hex?
  236.     je    get_number_5        ;yes.
  237.     call    get_digit        ;convert a character into an int.
  238.     jc    get_number_2        ;not a digit (neither hex nor dec).
  239.     xor    ah,ah
  240.     cmp    ax,bp            ;larger than our base?
  241.     jae    get_number_2        ;yes.
  242.  
  243.     push    ax            ;save the new digit.
  244.  
  245.     mov    ax,bp            ;multiply the low word by ten.
  246.     mul    cx
  247.     mov    cx,ax            ;keep the low word.
  248.     push    dx            ;save the high word for later.
  249.     mov    ax,bp
  250.     mul    bx
  251.     mov    bx,ax            ;we keep only the low word (which is our high word)
  252.     pop    dx
  253.     add    bx,ax            ;add the high result from earlier.
  254.  
  255.     pop    ax            ;get the new digit back.
  256.     add    cx,ax            ;add the new digit in.
  257.     adc    bx,0
  258.     jmp    get_number_1
  259. get_number_5:
  260.     mov    bp,16            ;change the base to hex.
  261.     jmp    get_number_1
  262. get_number_2:
  263.     dec    si
  264.     mov    [di],cx            ;store the parsed number.
  265.     clc
  266.     ret
  267. get_number_3:
  268.     stc
  269.     ret
  270.  
  271.  
  272.     public    skip_blanks
  273. skip_blanks:
  274.     lodsb                ;skip blanks.
  275.     cmp    al,' '
  276.     je    skip_blanks
  277.     cmp    al,HT
  278.     je    skip_blanks
  279.     dec    si
  280.     ret
  281.  
  282.  
  283. get_digit:
  284. ;enter with al = character
  285. ;return nc, al=digit, or cy if not a digit.
  286.     cmp    al,'0'            ;decimal digit?
  287.     jb    get_digit_1        ;no.
  288.     cmp    al,'9'            ;. .?
  289.     ja    get_digit_2        ;no.
  290.     sub    al,'0'
  291.     clc
  292.     ret
  293. get_digit_2:
  294.     or    al,20h
  295.     cmp    al,'a'            ;hex digit?
  296.     jb    get_digit_1
  297.     cmp    al,'f'            ;hex digit?
  298.     ja    get_digit_1
  299.     sub    al,'a'-10
  300.     clc
  301.     ret
  302. get_digit_1:
  303.     stc
  304.     ret
  305.  
  306. our_buffer    label    byte
  307.  
  308. code    ends
  309.  
  310.     end    start
  311.